<?php
/** 
 * X-Window
 *
 * @package Deenzo
 */
 
// No direct access
defined( "__DEENZO__" ) or die( "deenzo$" );

// Loading dependencies
coreutil( "string" ) or kill( "string$" );

/* Theme name */
define( "__THEME_NAME__", sysconfig( "template" ) );
/* Real Theme path */
define( "__THEME_DIR__", __DIR__ . "/themes/" . __THEME_NAME__ );

function enqueu( $mime, $source, $args ) {
    
    if ( !is_array( $source ) ) $source = array( $source );
    if ( is_string( $args   ) ) $args   = url_decode( $args, "-q" );
    
    foreach( $source as $src ) {
        if ( !preg_match("/^http/", $src) )
            $src = template_directory( false ) . "/$src";
        
        env("X11.net.$mime.", array( $src, $args ) );
    }
}

/** Enqueu JavaScript */
function javascript( $src , $args = "type=text/javascript" ) { 
    enqueu( "javascript", $src , $args ); 
}

function the_javascripts() {
	
	foreach ( (array) env("X11.net.javascript") as $js ) {
	
		list( $javascript, $args ) = $js;
		    	    
		echo "<script src = \"$javascript\" " . att( $args, "-x" ) . "></script>";
    }
}

/** Enqueu Stylesheet */
function stylesheet( $href, $args = "media=all" ) { 
    enqueu( "stylesheet", $href, $args );  
}

function the_stylesheets() {
	
    foreach ( (array) env("X11.net.stylesheet") as $css ) {
	    
	    list( $stylesheet, $args ) = $css;
	        
	     echo "<link href = \"$stylesheet\" " . att( $args, "-x" ) . " rel = \"stylesheet\" />";
	
	} 
}

function get_footer()  { 
    X11( "footer" ); 
} 

function get_header()  { 
    X11( "header" ); 
}

function get_sidebar() { 
    X11( "sidebar" ); 
}

function siteinfo( $sysconfig, $echoes = true ) {
    
    if ( $echoes )
        echo sysconfig( $sysconfig );
    else
        return sysconfig( $sysconfig );
    
}

function theme_directory() {
    return __DIR__ . "/themes/" . __THEME_NAME__;
}

function template_directory( $echoes = true ) { 
    
	/* Check if using, generally, INDEX.PHP as SITEURL */
	if ( preg_match("/\." . __PHP__ . "$/", $siteurl = sysconfig("siteurl") ) )
		$siteurl = dirname( $siteurl );
	
    $template_directory = $siteurl . "/themes/" . __THEME_NAME__;
    
    if ( $echoes )
        echo $template_directory;
    else
        return $template_directory;
}